﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.Catering_Page.yl.Daily
{
    public partial class SpareParts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadForm();
            }
        }
        protected void Rep_Plan_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.SpareParts().Delete(delID))
                {
                    LoadForm();
                }
            }           
        }
        public void LoadForm()
        { 
            try
            {
                DataTable dt_Plan = new Catering_Rules.SpareParts().GetList("ClassID = " + Session["ClassID"].ToString() + " and DevName ='" + Session["SapreParts"].ToString() + "'").Tables[0];
                dt_Plan.Columns.Add("tempId");
                //dt_Plan.Columns.Add("tempName");
                
                for (int i = 0; i < dt_Plan.Rows.Count; i++)
                {
                    dt_Plan.Rows[i]["tempId"] = i + 1;                    
                }
                this.Rep_Plan.DataSource = dt_Plan;
                this.Rep_Plan.DataBind();
            }
            catch
            {

            }
            
        }
        [WebMethod]
        public static string Add(string PName, string PType, string PNum, string hdn_DevName, string hdn_currentClassID)
        {
            Catering_Model.SpareParts _ce = new Catering_Model.SpareParts();
            _ce.DevName = hdn_DevName;
            _ce.PName = PName;
            _ce.PType = PType;
            _ce.PNum = PNum;
            _ce.ClassId = int.Parse(hdn_currentClassID);           
            new Catering_Rules.SpareParts().Add(_ce);
            return "OK";
        }
        [WebMethod]
        public static ArrayList Get(string _id)
        {
            ArrayList al = new ArrayList();
            Catering_Model.SpareParts md = new Catering_Rules.SpareParts().GetModel(Convert.ToInt32(_id));
            al.Add(md.Id);
            al.Add(md.PName);
            al.Add(md.PType);
            al.Add(md.PNum);
            return al;
        }
        [WebMethod]
        public static string Edit(string _id, string PName, string PType, string PNum)
        {
            int id = 0;
            int areaid = 0;
            Int32.TryParse(_id, out id);
            if (id <= 0) return "NO";

            Catering_Model.SpareParts _CE = new Catering_Model.SpareParts();

            _CE.Id = id;
            _CE.PName = PName;
            _CE.PType = PType;
            _CE.PNum = PNum;
            new Catering_Rules.SpareParts().Update(_CE);

            return "OK";
        }
    }
}